#pragma once

#include <cstdio>
#include <iostream>

class task
{
public:
    task()
    {}
    task(int x, int y, int op) : _x(x), _y(y), _op(op), _res(0), _st(RUN)
    {}

    int operator()()
    {
        switch (_op) 
        {
        case '+': _res = _x + _y; break;
        case '-': _res = _x - _y; break;
        case '*': _res = _x * _y; break;
        case '/': 
            if (_y == 0) _st = ERR;
            else _res = _x / _y;
            break;
        default: _st = ERR; break;
        }
        return _res;
    }

    std::string pformat()
    {
        char buff[64];
        snprintf(buff, 64, "%d %c %d = ?", _x, _op, _y);
        return buff;
    }

    std::string cformat()
    {
        char buff[64];
        if (_st) snprintf(buff, 64, "%d %c %d = %d", _x, _op, _y, _res);
        else     snprintf(buff, 64, "logic error");
        return buff;
    }

private:
    enum 
    {
        ERR = 0,
        RUN = 1,
    };
    int _x, _y, _op, _res, _st;
};
